package com.ibiaoke.boss.controller;

import com.ibiaoke.boss.entity.SysUser;
import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.goods.entity.XcxReduceGoods;
import com.ibiaoke.goods.entity.XcxReduceGoodsDetail;
import com.ibiaoke.goods.entity.vo.XcxReduceGoodsDetailVo;
import com.ibiaoke.goods.service.XcxReduceGoodsService;
import com.ibiaoke.system.dao.ShopDao;
import com.ibiaoke.system.entity.Shop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class BossXcxReduceGoodsController  extends BaseController {

    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    private XcxReduceGoodsService xcxReduceGoodsService;

    @Autowired
    private ShopDao shopDao;

    @RequestMapping("/addXcxReduceGoods")
    @ResponseBody
    public Res addXcxReduceGoods(@RequestBody List<XcxReduceGoodsDetailVo> xcxReduceGoodsDetailVo,
                        Integer payType,Double orderPrice,Double discounPrice,Double freightPrice,Double realPrice,
                        Integer shopId, Double onePrice){
        SysUser user = getLoginUser();
        Shop shop = shopDao.selectByPrimaryKey(shopId);
        xcxReduceGoodsService.addXcxReduceGoods(user.getUserName(),xcxReduceGoodsDetailVo,
                payType,orderPrice,discounPrice,freightPrice,realPrice,shopId,shop.getShopName(),onePrice);
        logger.info("系统用户{}正在Iphone端进行消库存操作",user.getUserName());
        return new Res();
    }

    @RequestMapping("/findXcxReduceGoods")
    @ResponseBody
    public Res findXcxReduceGoods(Integer shopId,Page page){
        List<XcxReduceGoods> xcxReduceGoodsList  = xcxReduceGoodsService.findXcxReduceGoods(shopId,page);
        return new Res().addResponse("xcxReduceGoodsList",xcxReduceGoodsList);
    }

    @RequestMapping("/findXcxReduceGoodsDetail")
    @ResponseBody
    public Res findXcxReduceGoodsDetail(String reduceCode){
        List<XcxReduceGoodsDetail> xcxReduceGoodsDetailList = xcxReduceGoodsService.findXcxReduceGoodsDetail(reduceCode);
        return new Res().addResponse("xcxReduceGoodsDetailList",xcxReduceGoodsDetailList);
    }


}
